package com.shouhuobao.take.mine;

import android.os.Bundle;
import android.os.Message;

import com.iseastar.BaseActivity2;
import com.iseastar.guojiang.consts.MsgID;
import com.iseastar.guojiang.logic.AppHttp;
import com.iseastar.guojiang.logic.JSON;
import com.iseastar.guojiang.model.ReqResult;
import com.shouhuobao.station.R;
import com.shouhuobao.take.model.ShopInfoBean;
import com.shouhuobao.take.utils.ImageDownUtils;

import java.util.ArrayList;

import droid.frame.view.xlist.SListView;

/**
 * Created by joker on 2017/9/8.
 * 店内物料下载
 */
public class ShopInfoDownActivity extends BaseActivity2 {

    private SListView mListView;
    private ShopInfoDownAdapter mAdapter = null;
    private ImageDownUtils imageDownUtils = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void findViewById() {
        setContentView(R.layout.activity_shop_info_down);
        super.findViewById();
        getAppTitle().setCommonTitle("店内物料下载");
        mListView = (SListView) findViewById(R.id.listview);
        mAdapter = new ShopInfoDownAdapter(initData(), getContext(), mListView);
        mListView.setAdapter(mAdapter);
        imageDownUtils = new ImageDownUtils(getContext());
    }

    @Override
    public boolean handleMessage(Message msg) {
        switch (msg.what) {
            //下载图片请求图片地址
            case MsgID.get_take_shop_image:
                cancelLoadingDialog();
                final ReqResult<?> result = JSON.parser(msg.obj);
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        if (checkLoginStatus(result)) {
                            imageDownUtils.downImageFile((String) result.getResult());
                        } else {
                            showToast(result.getMessage());
                        }
                    }
                });
                return true;

            default:
                return super.handleMessage(msg);
        }
    }

    private ArrayList<ShopInfoBean> initData() {
        int resId = getResources().getIdentifier("download_image_1", "drawable", getPackageName());
        int resId1 = getResources().getIdentifier("download_image_2", "drawable", getPackageName());
        int resId2 = getResources().getIdentifier("download_image_3", "drawable", getPackageName());
        ArrayList<ShopInfoBean> arrayList = new ArrayList<>();
        ShopInfoBean shopInfoBean = new ShopInfoBean("寄件用户到店投递二维码", "寄件用户到店后，使用火箭令牌上扫码功能或使用微信扫描该二维码可完成投递。", resId, 1);
        ShopInfoBean shopInfoBean1 = new ShopInfoBean("用户微信扫码取货牌", "取件用户扫描该二维码完成取件认证，领取包裹。快递员扫描物料下方小程序二维码打开火箭妥投小程序完成包裹签收。", resId1, 2);
        ShopInfoBean shopInfoBean2 = new ShopInfoBean("包裹货架编号（快递公司LOGO）", "快递员扫描图中小程序二维码打开火箭妥投小程序，完成签收，并根据快递公司分类将包裹放在对应货架编号的货架。", resId2, 3);
        arrayList.add(shopInfoBean);
        arrayList.add(shopInfoBean1);
        arrayList.add(shopInfoBean2);
        return arrayList;
    }

    /**
     * 下载物料图片
     */
    public void downShopImage(int type) {
        showLoadingDialog(null);
        AppHttp.getInstance().downShopImageData(type);
    }
}
